<?php //prd($tree->generate($listCategories,array('depth'=>2)));?>
<div class="listCategories index">
<?php echo $html->link(__('New category', true), array('action'=>'add'),array('class'=>'add_button')); ?>
<h2><?php __('Categories');?></h2>
<?php
echo "<div class='switcher'>";
echo __("Switch to ").$html->link("Listings Types",array("plugin"=>null,"controller"=>"listing_types","action"=>"index"));
echo "</div><br />";

$index->setData($listCategories, 'ListCategory');

$index->showFields(array('id','name',array('parent_node_name'=>__('Parent Category')),array('listingType'=>__('Listing Type'))));
$index->sortableFields(array('id','name','parent_node_name'));

$index->setAction(__('View'), array('action'=>'view', ':ListCategory.id'));
$index->setAction(__('Edit'), array('action'=>'edit', ':ListCategory.id'));
$index->setAction(__('Delete'), array('action'=>'delete', ':ListCategory.id'),$this->helpers,__('Warning! Deleting this category will delete all associated listings, reviews, comments and images. Are you sure you want to delete this category ?'));
$index->setAction(__('Add meta information'),'/admin/meta_information/setInfo/ListCategory/:ListCategory.id',array('onclick'=>"openAsPopup(this);return false;"));
$index->setAction(__('View Listings'), array('action'=>'index', 'controller'=>'listings', 'plugin'=>false,	'category::ListCategory.id'));

$index->addColumn('parent_id','setParentCategoryName');
$index->addColumn('listingType','setListingType');

$index->addButton(__("Delete Selected"),array("plugin"=>"categories","controller"=>"categories","action"=>"bulkDelete",'admin'=>true));

$index->setPaginateSeparator(' ');
echo $index->display();

function setListingType($record)
{
	App::import('Helper','Html');
	$Html = new HtmlHelper;
	return $Html->link($record['ListingType']['name'],'/admin/listing_types/view/'.$record['ListingType']['id']);
	
}

function setParentCategoryName($record)
{
	
	$Veiw = classRegistry::getObject('view');
	if(isset($Veiw->viewVars['categoryInfo'][$record['ListCategory']['parent_id']]))
	{
		return $Veiw->viewVars['categoryInfo'][$record['ListCategory']['parent_id']];
	}
	return __('N/A');
	//return $record[];
}
?>
</div>

